#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
    pid_t pid = fork();
    if(pid < 0)
    {
        perror("fail to fork");
        return -1;
    }
    else if(pid == 0)
    {
        for(int i = 0;i<3;i++)
        {
            printf("this is son-process\n");
            sleep(1);
        }
        exit(2);
    }
    else
    {
        int status = 0;
        wait(&status);
        if(WIFEXITED(status) != 0)
        {
            printf("this is father-process\n");
            printf("the value of status is %d\n",WEXITSTATUS(status));
        }
    }
    return 0;
}